﻿// JScript File
// check valid integer
function IsValidInt(s) {

    var valid = false;
    if (s != null && s != "" && !isNaN(s)) {
        valid = parseInt(s, 10) == s;
    }
    return valid;
}

// Kiem tra so thuc nam trong khoang minValue den maxValue
function CheckDouble(value, minValue, maxValue) {
    if (value.charAt(0) == "," || value.charAt(0) == "." || value.charAt(value.length - 1) == "," || value.charAt(value.length - 1) == ".") {
        return false;
    }
    if (value.indexOf(",,") > 0 || value.indexOf(".,") > 0 || value.indexOf(",.") > 0) {
        return false;
    }
    
    var valueWithoutComma = trimAll(replaceAll(value, ".", ""));
    valueWithoutComma = replaceAll(valueWithoutComma, ",", ".")
    if (isNaN(valueWithoutComma)) {
        return false;
    }
    if ((parseFloat(valueWithoutComma) < minValue) || (parseFloat(valueWithoutComma) > maxValue)) {
        return false;
    }
    return true;
}

//Ham kiem tra so nguyen nam trong khoang minValue den maxValue
function CheckIntR(value, minValue, maxValue) {
    if (value.charAt(0) == "," || value.charAt(0) == "." || value.charAt(value.length - 1) == "," || value.charAt(value.length - 1) == ".") {
        return false;
    }
    if (value.indexOf(",,") > 0) {
        return false;
    }
    var valueWithoutComma = trimAll(replaceAll(value, ",", ""));
    if (valueWithoutComma.charAt(0) == "+")
        valueWithoutComma = valueWithoutComma.substring(1, valueWithoutComma.length);
    if (!isInteger(valueWithoutComma)) {
        return false;
    }
    if ((parseFloat(valueWithoutComma) < minValue) || (parseFloat(valueWithoutComma) > maxValue)) {
        return false;
    }
    return true;
}

function ClientValidationDateTime(oSrc, args) {
    var value = trimAll(args.Value);
    var year;
    var result = true;
    if (value.length != 10) {
        result = false;
    }
    else {
        year = value.substring(6, 10);
        if (parseFloat(year) >= 1800) {
            if (!isDate(value, "dd/MM/yyyy")) {
                result = false;
            }
        }
        else {
            result = false;
        }
    }
    args.IsValid = result;
}
// JScript File
function DefineBrowser() {
    // Neu trinh duyet la IE thi return "IE"
    // Neu trinh duyet la FireFox thi return "FF"

    return checkbrowser();
}
function GetValueFromRadioButtonList(id) {
    var allInput = document.getElementsByTagName("input");
    var value = '';
    for (i = 0; i < allInput.length; i++) {
        var obj = allInput[i];
        if (obj.type == 'radio' && !obj.disabled && obj.name.indexOf(id) > 0) {
            if (obj.checked) {
                value = obj.value;
                break;
            }
        }
    }
    return value;
}
function GetValueFromRadioButtonListDisable(id) {
    var allInput = document.getElementsByTagName("input");
    var value = '';
    for (i = 0; i < allInput.length; i++) {
        var obj = allInput[i];
        if (obj.type == 'radio' && obj.name.indexOf(id) > 0) {
            if (obj.checked) {
                value = obj.value;
                break;
            }
        }
    }
    return value;
}
function SetStyleControl(control, value) {
    if (control)
        control.style.display = value;
}
function EnableControl(ctr, value) {
    if (ctr)
        ctr.enabled = value;
}
function SetValueForRadioButtonList(id, value) {
    var allInput = document.getElementsByTagName("input");
    for (i = 0; i < allInput.length; i++) {
        var obj = allInput[i];
        if (obj.type == 'radio' && !obj.disabled && obj.name.indexOf(id) > 0) {

            if (obj.value == value)
                obj.checked = true;
            else obj.checked = false;
        }
    }
}
